/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.webevo.gui.panels.sampler;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.webevo.exception.NoFileSelectedException;
import org.webevo.gui.controllers.ControllerUI_Sampler;

/**
 *
 * @author Djordje Gligorijevic
 */
public class PanelSampler extends javax.swing.JPanel {

    private ControllerUI_Sampler controller;

    /**
     * Creates new form PanelSampler
     */
    public PanelSampler() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnChooseDataset = new javax.swing.JButton();
        txtFieldDatasetFilePath = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtFieldSampleSize = new javax.swing.JTextField();
        btnCreateSample = new javax.swing.JButton();

        btnChooseDataset.setText("Choose dataset");
        btnChooseDataset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChooseDatasetActionPerformed(evt);
            }
        });

        txtFieldDatasetFilePath.setText("No dataset selected");

        jLabel1.setText("Enter desirable sample size: ");

        btnCreateSample.setText("Create sample");
        btnCreateSample.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreateSampleActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnCreateSample, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(txtFieldSampleSize, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                            .addComponent(txtFieldDatasetFilePath))
                        .addGap(18, 18, 18)
                        .addComponent(btnChooseDataset)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtFieldDatasetFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnChooseDataset, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtFieldSampleSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(btnCreateSample)
                .addContainerGap(69, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnChooseDatasetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChooseDatasetActionPerformed
        controller.getFileChooser();
    }//GEN-LAST:event_btnChooseDatasetActionPerformed

    private void btnCreateSampleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateSampleActionPerformed
        try {
            controller.createSample();
        } catch (NoFileSelectedException ex) {
            Logger.getLogger(PanelSampler.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(PanelSampler.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(PanelSampler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnCreateSampleActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChooseDataset;
    private javax.swing.JButton btnCreateSample;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField txtFieldDatasetFilePath;
    private javax.swing.JTextField txtFieldSampleSize;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the btnChooseDataset
     */
    public javax.swing.JButton getBtnChooseDataset() {
        return btnChooseDataset;
    }

    /**
     * @param btnChooseDataset the btnChooseDataset to set
     */
    public void setBtnChooseDataset(javax.swing.JButton btnChooseDataset) {
        this.btnChooseDataset = btnChooseDataset;
    }

    /**
     * @return the txtFieldDatasetFilePath
     */
    public javax.swing.JTextField getTxtFieldDatasetFilePath() {
        return txtFieldDatasetFilePath;
    }

    /**
     * @param txtFieldDatasetFilePath the txtFieldDatasetFilePath to set
     */
    public void setTxtFieldDatasetFilePath(javax.swing.JTextField txtFieldDatasetFilePath) {
        this.txtFieldDatasetFilePath = txtFieldDatasetFilePath;
    }

    /**
     * @return the txtFieldSampleSize
     */
    public javax.swing.JTextField getTxtFieldSampleSize() {
        return txtFieldSampleSize;
    }

    /**
     * @param txtFieldSampleSize the txtFieldSampleSize to set
     */
    public void setTxtFieldSampleSize(javax.swing.JTextField txtFieldSampleSize) {
        this.txtFieldSampleSize = txtFieldSampleSize;
    }

    /**
     * @return the controller
     */
    public ControllerUI_Sampler getController() {
        return controller;
    }

    /**
     * @param controller the controller to set
     */
    public void setController(ControllerUI_Sampler controller) {
        this.controller = controller;
    }
}
